$(document).ready(function () {

    var iUserId=addressUri.getParam('iUserId');


    $(function () { //加载时间轴
        $.ajax({
            url : baseUrl+'Tch/getPublicClass',
            dataType:'JSON',
            type:'Post',
            data:{'iUserId':iUserId},
            success:function (data) {
                timeLine.loadTimeLine($('#timeWraper'),data['data'],'公开课',data['showDelete'],data['showEdit']);
                $('.images').viewer();
            },
            error:function (result) {
                console.log(result);
            }
        })
    });

    //新建
    $('#new').click(function () {
        window.top.xhTop.showModal({
            title:'新建公开课',
            content:'<iframe src="'+baseUrl+'Tch/pClassForm?iUserId='+iUserId+'"  style="width: 100%;;border-style: none;padding: 0px;height:420px"  scrolling="yes"   ></iframe>',
            button:'提交',
            size:'lg',
            backClose:false
        });
    });



    //删除图片ajax
    $('#timeWraper').on('click','[id^=imageDelete_]',function () {
        var iPCId=$(this).attr("id").split("_")[1];
        var rmId=$(this).attr('id').split('_')[2];
        myWindow.initPopUp({text: '你确定要删除这张图片吗?'},function () {
            $.ajax({
                url:baseUrl+'Tch/ajaxDelete2',
                data:{'id':iPCId,'rmId':rmId},
                dataType:'json',
                type:'post',
                success:function (data) {
                    //根据数据更新
                    timeLine.loadTimeLine($('#timeWraper'),data['data'],'跟踪信息',data['showDelete'],data['showEdit']);
                    $('.images').viewer();
                },
                error:function (result) {
                    console.log(result);
                }
            });
        });

    });

    //删除图片ajax
    $('#timeWraper').on('click','[id^=fileDelete_]',function () {
        var iPCId=$(this).attr("id").split("_")[1];
        var rmId=$(this).attr('id').split('_')[2];
        myWindow.initPopUp({text: '你确定要删除这个附件吗?'},function () {
            $.ajax({
                url:baseUrl+'Tch/ajaxDelete2/fileDelete',
                data:{'id':iPCId,'rmId':rmId},
                dataType:'json',
                type:'post',
                success:function (data) {
                    //根据数据更新
                    timeLine.loadTimeLine($('#timeWraper'),data['data'],'跟踪信息',data['showDelete'],data['showEdit']);
                    $('.images').viewer();
                },
                error:function (result) {
                    console.log(result);
                }
            });
        });

    });

    //删除加载数据
    $('#timeWraper').on('click','[id^=delete_]',function () {
        var iPCId=$(this).attr("id").split("delete_")[1];
        myWindow.initPopUp({},function () {
            $.ajax({
                url : baseUrl+'Tch/delClass',
                data : {iPCId:iPCId},
                dataType : 'JSON',
                type : 'POST',
                success:function (data) {
                    location.reload();
                },
                error:function (result) {
                    console.log(result);
                }
            });
        });

    });


    //编辑加载数据
    $('#timeWraper').on('click','[id^=edit_]',function () {
        var iPCId=$(this).attr("id").split("edit_")[1];
        window.top.xhTop.showModal({
            title:'编辑公开课',
            content:'<iframe src="'+baseUrl+'Tch/pClassForm?iUserId='+iUserId+'&iPCId='+iPCId+'"  style="width: 100%;;border-style: none;padding: 0px;height:420px"  scrolling="yes"   ></iframe>',
            button:'提交',
            size:'lg',
            backClose:false
        });
    });
    $('#timeWraper').on('mousedown','[id^=fileList_] a ',function (e) {
        console.log($(this));
        var iPCId=$(this).attr("id").split("fileList_")[1];
        if(3 == e.which){
            alert('右键点击');
        }
    });

});